﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="UserManagerTest.cs" company="Concept Architecture">
//   (c) 2010 Muhammad Umer Farooq
// </copyright>
// <summary>
//   Summary description for UserManagerTest
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Hisaab.Business.Tests
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using AutoMapper;
    using Hisaab.Business.Entities;
    using Hisaab.Business.Mapping;
    using Hisaab.Common;
    using Hisaab.Data.Interfaces;

    using Microsoft.VisualStudio.TestTools.UnitTesting;

    using Moq;

    /// <summary>
    ///  Defines the <seealso cref="UserManagerTest"/> type.
    /// </summary>
    [TestClass]
    public class UserManagerTest
    {
        /// <summary>
        /// Initializes this instance.
        /// </summary>
        /// <param name="context">The context.</param>
        [ClassInitialize]
        public static void Initialize(TestContext context)
        {
            ObjectMapper.AddProfile(new BusinessMapping());
            Mapper.AssertConfigurationIsValid();
        }

        /// <summary>
        /// Constructors the should thorw if account repository is null.
        /// </summary>
        [TestMethod, ExpectedException(typeof(ArgumentNullException))]
        public void ConstructorShouldThorwIfUserRepositoryIsNull()
        {
            new UserManager(null);
        }

        /// <summary>
        /// Lists the should call user repository for list of users.
        /// </summary>
        [TestMethod]
        public void ListShouldCallUserRepositoryForListOfUsers()
        {
            var mockUserRepository = new Mock<IUserRepository>();
            IQueryable<Data.Entities.User> mockResult = new List<Data.Entities.User>().AsQueryable();

            mockUserRepository.Setup(x => x.Query(It.IsAny<Data.Entities.User>(), 12, 23))
                .Returns(mockResult)
                .Verifiable();

            var manager = new UserManager(mockUserRepository.Object);
            manager.List(new User(), 12, 23);

            mockUserRepository.VerifyAll();
        }
    }
}